#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
// #define ONLINE_JUDGE
#define INF 0x3f3f3f3f
const int N = 15, M = 9;
int n, m = 8;
int s[M][M];
double f[M][M][M][M][N]; // f[x1][y1][x2][y2][k] 矩阵[x1,x2,y1,y2]划分为k块的n*tao方
double X;

double get(int x1, int y1, int x2, int y2)  //求该矩阵的 n\sigma^2(计算公式)
{
    double sum = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1] - X;
    return sum * sum / n;
}

double dp(int x1, int y1, int x2, int y2, int k)
{
    double &v = f[x1][y1][x2][y2][k];
    if (v >= 0) return v; //记忆化搜索
    if (k == 1) return v = get(x1, y1, x2, y2);  //更新初始状态

    v = INF; //初始化为无穷大
    for (int i = x1; i < x2; i ++ ) //枚举横着切
    {
        v = min(v, dp(x1, y1, i, y2, k - 1) + get(i + 1, y1, x2, y2));
        v = min(v, dp(i + 1, y1, x2, y2, k - 1) + get(x1, y1, i, y2));
    }
    for (int i = y1; i < y2; i ++ ) //枚举竖着切
    {
        v = min(v, dp(x1, y1, x2, i, k - 1) + get(x1, i + 1, x2, y2));
        v = min(v, dp(x1, i + 1, x2, y2, k - 1) + get(x1, y1, x2, i));
    }
    return v;
}
int main()
{

    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
	cin.tie(0);


    cin >> n;
    for (int i = 1; i <= m; i ++ )
        for (int j = 1; j <= m; j ++ ){
            cin >> s[i][j];
            s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1]; //预处理前缀和
        }
    
    //初始化所有状态
    memset(f, -1, sizeof f);
    
    //计算x的平均值
    X = (double) s[m][m] / n;

    //记忆化搜索
    printf("%.3lf\n", sqrt(dp(1, 1, 8, 8, n)));
    return 0;
}
